/*
 * Copyright 2012 modjn Project
 *
 * The modjn Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package com.takeoff.iot.modbus.server.entity.func.request;


import com.takeoff.iot.modbus.server.entity.func.AbstractFunction;
import com.takeoff.iot.modbus.server.exception.DataConvertException;
import com.takeoff.iot.modbus.server.utils.HexUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.EmptyByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author heyayun
 * @description 读线圈
 * @date 2021/3/23 9:44
 */
public class ReadDataRequest extends AbstractFunction {

    /**
     * startingAddress = 0x0000 to 0xFFFF
     * quantityOfCoils = 1 - 2000 (0x07D0)
     */
    public ReadDataRequest() {
        super(READ_COILS);
    }

    public ReadDataRequest(int startingAddress, int quantityOfCoils) {
        super(READ_COILS, startingAddress, quantityOfCoils);
    }

    public int getStartingAddress() {
        return address;
    }

    public int getQuantityOfCoils() {
        return value;
    }

//    @Override
//    public ByteBuf encode() {
//        ByteBuf buf = Unpooled.buffer();
//        try {
//            byte b = HexUtil.hexToByte("010300110001");
//            buf.writeByte(b);
//        } catch (DataConvertException e) {
//            throw new RuntimeException(e);
//        }
//        return buf;
//    }

    @Override
    public String toString() {
        return "ReadCoilsRequest{" + "startingAddress=" + address + ", quantityOfCoils=" + value + '}';
    }
}
